﻿
using MediatR;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.Slaughter
{
    public class SlaughterCreateHandler : IRequestHandler<SlaughterCreateCommond, Rulst>
    {

        private readonly IbaseRpository<slaughterMess> _slaughhtermess;

        public SlaughterCreateHandler(IbaseRpository<slaughterMess> slaughhtermess)
        {
            _slaughhtermess = slaughhtermess;
        }

        public async Task<Rulst> Handle(SlaughterCreateCommond request, CancellationToken cancellationToken)
        {

            var query = new Rulst() { Code = (int)Reult.success };

            var list=_slaughhtermess.Query().Where(x=>x.ProDuctionBasicid==request.ProDuctionBasicid).FirstOrDefault();


            if(list!=null)
            {
                list.Slaughterlot = request.Slaughterlot;
                list.SlaugherWeight = request.SlaugherWeight;
                list.SlaugherComeTime = request.SlaugherComeTime;
                list.SlaugherTime = request.SlaugherTime;
                list.ProDuctionBasicid = request.ProDuctionBasicid;
                var one= _slaughhtermess.update(list);
                query.Code = one;
                query.MSG = "修改成功";
            }
            else
            {
                var slughter = new slaughterMess()
                {
               
                    Slaughterlot = request.Slaughterlot,
                    SlaugherWeight = request.SlaugherWeight,
                    SlaugherComeTime = request.SlaugherComeTime,
                    SlaugherTime = request.SlaugherTime,
                    ProDuctionBasicid = request.ProDuctionBasicid,
                    slaughterid=0,
                    SetupTime=new DateTime(),
                    BossIntroMess="",
                    BossName="",
                    Cityid=0,
                    countyid=0,
                    Provinceid=0,
                };
                var two= _slaughhtermess.Add(slughter);
                query.Code = two;
                query.MSG = "添加成功";
            }
            return query;



        }
    }
}
